<template>
	<view class="main u-page">
		<view class="head">
			<view class="head_box">
				<view class="tag_box">
					<view class="king_table">
						<text @click="operation(1)" :class="tableactive == 1 ? 'active' : 'inactive'">邀请记录</text>
						<text @click="operation(2)" :class="tableactive == 2 ? 'active' : 'inactive'">投递记录</text>
						<text @click="operation(3)" :class="tableactive == 3 ? 'active' : 'inactive'">浏览记录</text>
					</view>
				</view>
			</view>
		</view>
		<view class="main_content">
			<block v-for="(item,index) in list" v-if="list.length > 0">
				<view class="company_box">
					<view class="company_item_box" @click="goto('/pages/enterprise/resumedetails?id='+item.uid+'&source=1')">
						<view class="company_name" v-if="tableactive < 3">{{tableactive == 1 ? '邀请岗位：' : '投递岗位：'}}{{item.position}}</view>
						<view class="company_job">
							姓名：{{item.name || ""}}
						</view>
						<view class="company_job">技能：{{item.skill || ""}}</view>
						<view class="company_job">要求：{{item.salary || ""}}</view>
						<view class="company_job">时间：{{item.create_time || ""}}</view>
						<view class="company_job"  v-if="tableactive > 3">
							状态：{{item.status==1 ? '待面试' : item.status==2 ? '已面试' : item.status==3 ? '已取消' : item.status==0 ? '待处理' : '已拒绝'}}
						</view>
						<view class="company_job" v-if="tableactive > 3 && item.status == 1">面试时间：{{item.interview_time || ""}}</view>
					</view>
					<view class="company_logo">
						<view class="company_logo_item">
							<image :src="item.sex == '男' ? '/static/img/man.png' : '/static/img/woman.png'"></image>
						</view>
						<view v-if="tableactive == 1" class="jsob_yao_item" @click="quxiaodelivery(item.id)">
							取消邀请
						</view>
						<view v-if="tableactive == 2" style="display: flex;justify-content: space-between;">
							<view class="jsob_yao_item" @click="yuedelivery(item.id)">
								面试
							</view>
							<view class="jsob_yao_item" style="background-color: #999;" @click="jujue(item.id)">
								拒绝
							</view>
						</vuew>
						</view>  
					</view>
				</view>
			</block>
			<block v-else>
			<u-empty mode="data"> </u-empty>
			</block>
		</view>
		<u-modal
			title="邀请面试"
			:show="yaoqingModal"
			showCancelButton
			asyncClose
			@confirm="yaoqingconfirm"
			@cancel="() => yaoqingModal = false"
		>
			<u--form
				labelPosition="left"
				:model="form"
				ref="form"
			>
				<u-form-item
					label="面试时间"
					prop="interview_time"
					labelWidth="80"
					@click="showDatetimePicker"
				>
					<u--input
						v-model="yaoqingform.interview_date"
						border="none"
						placeholder="面试时间"
					></u--input>
				</u-form-item>
			</u--form>
		</u-modal>
		<u-datetime-picker
			:show="timeshow"
			v-model="form.interview_date"
			mode="datetime"
			closeOnClickOverlay
			@confirm="timeconfirm"
			@cancel="timecancel"
			@close="timeclose"
		></u-datetime-picker>
		<u-picker
			:show="showposition"
			:columns="positionList"
			keyName="position"
			@cancel="positioncancel"
			@confirm="positionconfirm"
		></u-picker>
		<Tabbar :count="10"></Tabbar>
	</view>
</template>

<script>
	import Tabbar from "@/components/entTabbar"
	import { formatTime } from '@/utils/utils'
	import { imgURL } from '@/utils/config'
	import { getPositionList } from '@/api/position.js'
	import { quxiaodelivery,getdelivery,getView,getinvitation,handleDelivery } from '@/api/enterprise.js'
	
	export default {
		components: {
			Tabbar
		},
		data() {
			return {
				tableactive:1,
				imgURL:imgURL,
				yaoqingModal:false,
				showposition:false,
				timeshow:false,
				list: [],
				label:['应届生','就职人才'],
				form:{
					page:1,
					pagesize:20,
					total:0,
					keyword:'',
				},
				yaoqingform:{
					id:'',
					status:1,
					interview_time:'',
					interview_date:''
				},
				positionList:[],
				defaultIndex:[[]]
			}
		},
		onLoad() {
			this.getinvitationList()
		},
		methods: {
			operation(tableactive){
				this.form = {
					page:1,
					pagesize:20,
					total:0,
					keyword:'',
				}
				this.tableactive = tableactive
				switch(tableactive){
					case 1:
						this.getinvitationList()
						break;
					case 2:
						this.getdeliveryList()
						break;
					default:
						this.getViewList()
						break;
				}
			},
			
			//获取邀请信息
			getinvitationList() {
				getinvitation(this.form).then(res=>{
					if(res.code == 200){
						this.list = res.data.data
						this.form.total = res.data.total
					}
					else{
						return uni.showToast({
							icon: 'none',
							title: res.msg
						});
					}
				})
			},
			
			//获取投递信息
			getdeliveryList() {
				getdelivery(this.form).then(res=>{
					if(res.code == 200){
						this.list = res.data.data
						this.form.total = res.data.total
					}
					else{
						return uni.showToast({
							icon: 'none',
							title: res.msg
						});
					}
				})
			},
			
			//获取邀请信息
			getViewList() {
				getView(this.form).then(res=>{
					if(res.code == 200){
						this.list = res.data.data
						this.form.total = res.data.total
					}
					else{
						return uni.showToast({
							icon: 'none',
							title: res.msg
						});
					}
				})
			},
			
			//邀请弹窗
			quxiaodelivery(id) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定要取消邀请吗？',
					success: function (res) {
						if (res.confirm) {
							quxiaodelivery({id:id}).then(res=>{
								if(res.code == 200){
									uni.showToast({
										title:res.msg,
										duration: 2000,
										icon:'none',
										success() {
											that.getinvitationList()
										}
									});
								}
								else{
									uni.showToast({
										icon: 'none',
										title: res.msg
									});
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			
			//提交邀请
			yuedelivery(id){
				this.yaoqingform.id = id
				this.yaoqingform.status = 2
				this.yaoqingModal = true
			},
			//showPicker
			showPicker(){
				this.showposition = true
			},
			positionclose() {
				this.showposition = false
			},
			positionconfirm(e) {
				this.showposition = false
				this.yaoqingform.position_name = e.value[0].position
				this.yaoqingform.position_id = e.value[0].position_id
			},
			positioncancel() {
				this.showposition = false
			},
			//时间弹窗关闭
			timeclose() {
				this.timeshow = false
			},
			//开启时间弹窗
			showDatetimePicker() {
				this.timeshow = true
			},
			timecancel() {
				this.timeshow = false
			},
			timeconfirm(e) {
				this.timeshow = false
				this.yaoqingform.interview_time = e.value/1000
				const timeFormat = uni.$u.timeFormat
				this.yaoqingform.interview_date = timeFormat(e.value, 'yyyy-mm-dd hh:MM')

			},
			
			yaoqingconfirm(){
				let that = this
				handleDelivery(that.yaoqingform).then(res=>{
					this.yaoqingModal = false
					if(res.code == 200){
						uni.showToast({
							title:res.msg,
							duration: 2000,
							icon:'none',
							success() {
								that.getdeliveryList()
							}
						});
					}
					else{
						uni.showToast({
							icon: 'none',
							title: res.msg
						});
					}
				})
			},
			
			goto(tourl) {
				uni.navigateTo({
					url: tourl
				});
			},
			
			//拒绝
			jujue(id){
				this.yaoqingform.status = 3
				this.yaoqingform.id = id
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定要拒绝人才的投递吗？',
					success: function (res) {
						if (res.confirm) {
							handleDelivery(that.yaoqingform).then(res=>{
								if(res.code == 200){
									uni.showToast({
										title:res.msg,
										duration: 2000,
										icon:'none',
										success() {
											that.getdeliveryList()
										}
									});
								}
								else{
									uni.showToast({
										icon: 'none',
										title: res.msg
									});
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
		},
	}
</script>

<style lang="scss">
	.head{
		background-image: url('');
		background-repeat:no-repeat;
		background-attachment:fixed;
		background-size:cover;
		width: 100%;
		height: 420rpx;
		display: block;
		image{
			width: 100%;
			height: 100%;
		}
		.head_box{
			padding-top: 30rpx;
			width: 100%;
			.job_box{
				margin: 0 40rpx;
				height: 100rpx;
				line-height: 100rpx;
				text-align: center;
				font-size: 48rpx;
				color: #fff;
				text{
					color: #43e4f8;
				}
			}
			.tag_box{
				margin: 0 60rpx;
				height:80rpx;
				line-height: 80rpx;
				color: #fff;
				font-size: 26rpx;
				.king_table{
					margin: 90rpx 0rpx;
					.inactive{
						border: 1px solid #f4f4f4;
						padding: 16rpx 40rpx;
						color: #fff;
						margin-right: 20rpx;
					}
					.active{
						margin-right: 20rpx;
						border: 1px solid #989dfd;
						background-color: #989dfd;
						padding: 16rpx 40rpx;
						color: #fff;
					}
				}
			}
		}
	}
	.main_content{
		margin-top: -200rpx;
		.company_box{
			background-color: #f9f9f9;
			display: flex;
			justify-content: space-between;
			margin: 20rpx 40rpx;
			padding: 20rpx 40rpx;
			font-size: 24rpx;
			color: #000;
			.company_logo{
				display: flex;
				flex-wrap: wrap;
				justify-content: center;
				align-items: center;
				.jsob_yao_item{
					border: 1px solid #f3f3f3;
					background-color: #989dfd;
					color: #fff;
					font-size: 28rpx;
					margin-top: 20rpx;
					padding: 10rpx;
					width: 100%;
					text-align: center;
				}
				.company_logo_item{
					width:90rpx; 
					height:90rpx;
					position: relative;
					image{
						max-width: 100% !important;
						max-height: 100% !important;
					}
				}
			}
			.company_item_box{
				.company_name{
					width:380rpx;
					font-size: 34rpx;
					height: 60rpx;
					line-height: 60rpx;
					white-space:nowrap;
					overflow:hidden;
					text-overflow:ellipsis;
				}
				.company_handle{
					margin: 20rpx;
					.handle_shenqin{
						width: 200rpx;
						line-height: 80rpx;
					}
				}
				
				.company_job,.company_addr,.company_salary{
					display: flex;
					align-items: center;
					font-size: 28rpx;
					height: 50rpx;
					width: 380rpx;
					white-space:nowrap;
					overflow:hidden;
					text-overflow:ellipsis;
					color: #777777;
				}
				.company_intro{
					line-height: 50rpx;
					color: #777777;
					margin-bottom: 20rpx;
				}
			}
		}
	}
	.foot{
		background-color: #000;
	}
</style>